package org.bing.flex.helper {
    import mx.formatters.DateFormatter;

    public class DateHelper {

        private static var FMT:String="YYYY-MM-DD LL:NN:SS";
        private static var formater:DateFormatter=new DateFormatter();

        public static function lastDayOfQuarter(date:Date, quarter:int):Date {
            if (quarter == 1) {
                date.month=2;
                date.date=31;
            } else if (quarter == 2) {
                date.month=5;
                date.date=30;
            } else if (quarter == 3) {
                date.month=8;
                date.date=30;
            } else if (quarter == 4) {
                date.month=11;
                date.date=31;
            }
            return date;
        }

        public static function lastQuarterLastDay():Date {
            var dt:Date=new Date();
            var qt:int=dt.getMonth() / 3;
            if (qt == 0) {
                dt.fullYear=dt.fullYear - 1;
                qt=4;
            }
            return lastDayOfQuarter(dt, qt);
        }

        public static function format(dt:Date, fs:String):String {
            var fmt:DateFormatter=new DateFormatter();
            fmt.formatString=fs;
            return fmt.format(dt);
        }
    }
}